package com.auxgroup.smarthome.inner.controller;

import com.auxgroup.bridge.business.inner.dto.BusiAppIndexPageDto;
import com.auxgroup.bridge.business.inner.vo.AppIndexPageVo;
import com.auxgroup.bridge.business.inner.vo.CurrentAppIndexPageVo;
import com.auxgroup.smarthome.inner.service.AppIndexPageService;
import com.auxgroup.smarthome.web.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by niuGuangzhe on 2017/8/2.
 */
@Api(description = "App首页相关接口", tags = "app首页相关接口")
@RestController
@Validated
public class AppIndexPageController {

    @Autowired
    private AppIndexPageService appIndexPageService;

    @ApiOperation(value = "保存app首页文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "zipUri", value = "zip包地址", required = true, paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "htmlUri", value = "预览地址页面", required = true, paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "releaseUser", value = "发布者", required = true, paramType = "form", dataType = "string")
    })
    @PostMapping(value = "/index_page/save")
    public ApiResponse<AppIndexPageVo> saveAppIndexPage(@ApiIgnore @Valid BusiAppIndexPageDto busiAppIndexPageDto) {
        return appIndexPageService.saveAppIndexPage(busiAppIndexPageDto);
    }

    @ApiOperation(value = "app首页文件发布接口", notes = "首页发布使用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "indexPageId", value = "主键", required = true, paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "releaseUser", value = "发布者", required = true, paramType = "form", dataType = "string")
    })
    @PostMapping(value = "/index_page/relese")
    public ApiResponse publish(@NotBlank(message="indexPageId不能为空") String indexPageId, @NotBlank(message="releseUser不能为空") String releseUser) {
        return appIndexPageService.publishAppIndexPage(indexPageId, releseUser);
    }

    @ApiOperation(value = "app首页文件查询列表")
    @GetMapping(value = "/index_page/history")
    public ApiResponse<List<AppIndexPageVo>> findVersionHistory() {
        return appIndexPageService.getAppIndexPageList();
    }

    @ApiOperation(value = "获取app最新的首页发布版本")
    @GetMapping(value = "/index_page/current_version")
    public ApiResponse<AppIndexPageVo> getlatestIndexPage() {
        return appIndexPageService.getlatestIndexPage();
    }

    @ApiOperation(value = "获取web最新的首页版本")
    @GetMapping(value = "/index_page/current_web_version")
    public ApiResponse<CurrentAppIndexPageVo> getlatestIndexPageVersion() {
        return appIndexPageService.getlatestIndexPageVersion();
    }

}
